// 城市，市区选择器

import citys from './city'
const city = [] // 城市
Object.keys(citys).map((item) => {
  if (citys[item]['市辖区']) {
    city.push(item)
  } else {
    city.push(...Object.keys(citys[item]))
  }
})

export default {
  data() {
    return {
      city,
      area: []
    }
  },
  watch: {
    // 根据城市的变化获取市区的数组
    queryData: {
      deep: true,
      immediate: true,
      handler(val) {
        if (citys[val.province]) {
          this.area = [...citys[val.province]['市辖区']]
        } else {
          Object.keys(citys).filter((item) => {
            if (!Object.keys(citys[item]).includes(val.province)) return
            Object.keys(citys[item]).map((item1) => {
              if (item1 !== val.province) return
              this.area = [...citys[item][item1]]
            })
          })
        }
      }
    }
  }
}
